

import axios from 'axios'


//创建axios 实例


let servicer = axios.create({
    baseURL:'https://www.fastmock.site/mock/e7cbc7e067b03e9292851c12670baa1a/react',
    timeout:6000
})


// 获取到token 

servicer.interceptors.request.use(config=>{
      //config  =>请求的配置对象
  // 后端 =》 1 外部页面   2内部页面 
  
    config.headers['token']  = sessionStorage.getItem('token')?sessionStorage.getItem('token'):''
    return config
},err=>{
      console.log(err);
      
})


servicer.interceptors.response.use(
    res=>{

        // res =>axios响应对象
        return res.data
    },
    err=>{
        console.log(err);
        
  }
)


export default  servicer